<template>
  <!-- 预览的弹层----------------||=================== -->
  <el-dialog
    title="题目预览"
    :visible="dialogVisible"
    width="900"
    @close="handleClose"
  >
    <el-row :gutter="20">
      <el-col :span="6">【题型】：{{ questionTypeShow }}</el-col>
      <el-col :span="6">【编号】：{{ SonList.id }}</el-col>
      <el-col :span="6">【难度】：{{ difficultyShow }}</el-col>
      <el-col :span="6">【标签】：{{ SonList.tags }}</el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="6">【学科】：{{ SonList.subjectName }}</el-col>
      <el-col :span="6">【目录】{{ SonList.directoryName }}</el-col>
      <el-col :span="6">【方向】：{{ SonList.direction }}</el-col>
    </el-row>
    <hr />
    【题干】：
    <div v-html="SonList.question" style="color: blue"></div>
    <div v-if="SonList.questionType !== '3'">
      <div style="padding-bottom: 5px">
        {{ SonList.questionType | tx }} 选项：（以下选中的选项为正确答案）
      </div>
      <div
        v-for="item in SonList.options"
        :key="item.code"
        style="padding: 8px 0"
      >
        <el-radio
          v-if="SonList.questionType === '1'"
          :value="item.isRight"
          :label="1"
          >{{ item.title }}</el-radio
        >
        <el-checkbox
          v-if="SonList.questionType === '2'"
          :value="item.isRight ? true : false"
          >{{ item.title }}</el-checkbox
        >
      </div>
    </div>
    <hr />
    <div>
      <span
        >【参考答案】：<el-button
          type="danger"
          size="medium"
          @click="clickVideoShow"
          >视屏答案预览</el-button
        ></span
      >

      <div v-if="videoShow" style="margin-top: 20px">
        <video
          ref="video"
          :src="SonList.videoURL"
          controls
          style="width: 300px"
        ></video>
      </div>
    </div>
    <hr />
    <el-row :gutter="20">
      <el-col class="box" :span="6"
        >【答案解析】:<span v-html="SonList.answer"></span
      ></el-col>
    </el-row>
    <hr />
    <el-row>
      <el-col>【题目备注】：{{ SonList.remarks }}</el-col>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { difficulty, questionType } from '@/api/hmmm/constants.js'

export default {
  data () {
    return {
      videoShow: false
      // checkedCities: []
    }
  },

  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    SonList: {
      type: Object,
      required: true
    }
  },
  created () {
    // setTimeout(() => {
    //   // console.log(this.SonList)
    // }, 2000)
  },
  computed: {
    questionTypeShow () {
      const o = questionType.find(
        (item) => item.value === Number(this.SonList.questionType)
      )
      return o ? o.label : ''
    },
    difficultyShow () {
      const o = difficulty.find(
        (item) => item.value === Number(this.SonList.difficulty)
      )
      // console.log(o)
      return o ? o.label : ''
    }
  },
  filters: {
    nd (value) {
      if (value) return difficulty.find((item) => item.value === +value).label
    },
    tx (value) {
      if (value) { return questionType.find((item) => item.value === +value).label + '题' }
    }
  },
  methods: {
    // 子传父
    handleClose () {
      this.$emit('update:dialogVisible', false)
      this.videoShow = false
    },
    clickVideoShow () {
      // 视屏显示
      this.videoShow = !this.videoShow
      this.$refs.video.play()
    }
  }
}
</script>

<style scoped lang="scss">
.box {
  display: flex !important;
  ::v-deep {
    p {
      margin: 0px !important;
    }
  }
}
</style>
